package com.njit.campuslifeboot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.njit.campuslifeboot.entity.dto.AddCommentDTO;
import com.njit.campuslifeboot.entity.dto.CommentItem;
import com.njit.campuslifeboot.entity.po.LifeInfoComment;
import com.njit.campuslifeboot.mapper.LifeInfoCommentMapper;
import com.njit.campuslifeboot.mapper.UserMapper;
import com.njit.campuslifeboot.service.ILifeInfoCommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Axin
 * @since 2022-11-08
 */
@Service
public class LifeInfoCommentServiceImpl extends ServiceImpl<LifeInfoCommentMapper, LifeInfoComment> implements ILifeInfoCommentService {

    @Autowired
    private LifeInfoCommentMapper lifeInfoCommentMapper;
    @Autowired
    private UserMapper userMapper;

    @Override
    public boolean addComment(AddCommentDTO addCommentDTO, Integer id) {
        LifeInfoComment lifeInfoComment = new LifeInfoComment();
        lifeInfoComment.setComment(addCommentDTO.getComment());
        lifeInfoComment.setLifeInfoId(addCommentDTO.getLifeInfoId());
        lifeInfoComment.setUserId(id);
        lifeInfoComment.setCreateTime(LocalDateTime.now());
        int insert = lifeInfoCommentMapper.insert(lifeInfoComment);
        return insert > 0;
    }

    @Override
    public List<CommentItem> getComments(Integer infoId) {
        List<CommentItem> commentItems = lifeInfoCommentMapper.getComments(infoId);
        return commentItems;
    }
}
